package com.mes.service.warehouse;

import com.mes.entity.User;
import com.yy.base.common.dao.Dao;
import com.yy.base.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DdXbkSjListService {
    @Autowired
    private Dao dao;


    //根据物料ID查询对应仓库
    public List<Map<String,Object>> selectWarehouseCode(String id) {
        String sql = " select ck.shipper_code as CKCODE from wms_warehouse_product wl , m_warehouse ck  " +
                " where wl.m_warehouse_id = ck.m_warehouse_id " +
                " and wl.m_product_id = ? " ;

        return dao.query(sql,id);
    }


    //根据传过来的RFID号查询item表中是否存在RFID
    public List<Map<String,Object>> getBatchnorLists(String batch_no) {

        return dao.query("SELECT  \n" +
                "   mx.wms_storage_batch_item_id as ITEMID, pc.emes_color_id as YSID,  pc.wms_storage_batch_id as BATCHID, \n" +
                " wl.m_product_id as WLID, wl.value as WLVALUE, wl.name as WLNAME,to_char(now(), 'yyyy-mm-dd hh24:mi:ss') as TIMES , \n" +
                " pc.emes_size_id as CMID , mx.status as STATUS \n" +
                "FROM  \n" +
                " wms_storage_batch pc,  \n" +
                " m_product wl ,  \n" +
                " wms_storage_batch_item mx  \n" +
                "WHERE  \n" +
                " pc.m_product_id = wl.m_product_id  \n" +
                " and pc.wms_storage_batch_id = mx.wms_storage_batch_id  \n" +
                " and mx.code = '"+batch_no+"'  \n" +
                " group by   wl.m_product_id ,   pc.emes_size_id  ,mx.status ,mx.wms_storage_batch_item_id," +
                " pc.wms_storage_batch_id,  pc.emes_color_id,wl.name ");
    }


    /**
     * 往batch_up表中插入信息
     * @return
     */
    @SuppressWarnings("unchecked")
    public boolean inStorageUp(String uuid , String type, String code , User user,String Status, String productid ,String sizeid ,String colorid,String LeftITEMID,String RightITEMID,String leftRfid,String rightRfid) {
        boolean result = false;
        String uuids = StringUtil.getUUID();

        String sql = "insert into wms_storage_batch_up "
                + " (wms_storage_batch_up_ID,Wms_Storage_Batch_ID,Type,Code, "
                + " AD_CLIENT_ID, AD_ORG_ID,ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,status,m_product_id,emes_size_id,emes_color_id,left_item,right_item,rfid_left,rfid_right)" +
                " values(?,?,?,?,?,?,?,now(),?,now(),?,?,?,?,?,?,?,?,?)";


        result =  dao.executeSql(sql, uuids,uuid,type,code, user.getClientId(), user.getOrgId(), "Y", user.getId(), user.getId(),Status,productid,sizeid,colorid,LeftITEMID,RightITEMID,leftRfid,rightRfid) > 0;

        return result;
    }
}
